import Vue from "vue";
import ConfirmModal from "@/components/confirmModal";

const Component = Vue.extend(ConfirmModal);
let instance = "";

export default ({ key = "", title = "", content = "", onOk = () => {} }) => {
  if (typeof window === "undefined") return;
  if (!instance) {
    instance = new Component({
      el: document.createElement("div")
    });
    document.body.appendChild(instance.$el);
  }
  Vue.nextTick(() => {
    if (instance) {
      instance.confirm({
        key,
        title,
        content,
        onOk
      });
    }
  });
};
